package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Games;
import com.ruoyi.system.service.IGamesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 游戏信息Controller
 * 
 * @author ruoyi
 * @date 2025-01-13
 */
@RestController
@RequestMapping("/system/games")
public class GamesController extends BaseController
{
    @Autowired
    private IGamesService gamesService;

    /**
     * 查询游戏信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:games:list')")
    @GetMapping("/list")
    public TableDataInfo list(Games games)
    {
        startPage();
        List<Games> list = gamesService.selectGamesList(games);
        return getDataTable(list);
    }

    /**
     * 导出游戏信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:games:export')")
    @Log(title = "游戏信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Games games)
    {
        List<Games> list = gamesService.selectGamesList(games);
        ExcelUtil<Games> util = new ExcelUtil<Games>(Games.class);
        util.exportExcel(response, list, "游戏信息数据");
    }

    /**
     * 获取游戏信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:games:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gamesService.selectGamesById(id));
    }

    /**
     * 新增游戏信息
     */
    @PreAuthorize("@ss.hasPermi('system:games:add')")
    @Log(title = "游戏信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Games games)
    {
        return toAjax(gamesService.insertGames(games));
    }

    /**
     * 修改游戏信息
     */
    @PreAuthorize("@ss.hasPermi('system:games:edit')")
    @Log(title = "游戏信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Games games)
    {
        return toAjax(gamesService.updateGames(games));
    }

    /**
     * 删除游戏信息
     */
    @PreAuthorize("@ss.hasPermi('system:games:remove')")
    @Log(title = "游戏信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gamesService.deleteGamesByIds(ids));
    }
}
